//获取app实例
const app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    baseGoodsImgUrl: 'https://jrtest.0791jr.com/data/attachment/item/',
    state: 0,
    logistics: [],//物流信息
    goodsImg: null, //图片
    state: 0, //
    LogisticName: "",//
    LogisticCode: null,//单号
    logistics:[] //物流信息
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    let orderId = options.orderid;
    const urlData = options.type == 1 ? 'integral&a=wl' : 'Order&a=wl';
    wx.showLoading({title: '请稍后...',})
    wx.request({
      url: app.baseURL + urlData,
      data: {order_id: orderId},
      success: (res)=> {
        const isState = res.data.trace_info.State;
        const traces = res.data.trace_info.Traces;
        wx.hideLoading();
        this.setData({ 
          goodsImg: res.data.item_info.img || res.data.item_info[0].img,
          state: isState,
          LogisticName: res.data.wuliu,
          LogisticCode: res.data.trace_info.LogisticCode,
          logistics: traces.reverse()  //reverse()方法将数组反转
        })
      },
      fail: (res) => {
        wx.hideLoading();
        wx.showToast({ title: '网络错误', icon: 'none' })
      }
    })
  }
})